const YoloDetector = require('../yolo');
const APP = require('../APP');
class index{
    androidBot = null;
    constructor(client){
        this.GameClient = client;
        this.androidBot = this.GameClient.androidBot;
    }
    async run(){
        // 寻找标志 - 开始游戏按钮
        let done = false;
        while(!done){
            let data = await YoloDetector.screen(this.androidBot);
            let startGame = APP.findClass_v2(data, 'login_btn_startGame');
            if(startGame){
                await startGame.click();
                continue;
            }
            if(APP.findClass_index(data, 'loding')){
                await APP.sleep(1000);
                continue;
            }
            let pop = APP.findClass_index(data, 'pop');
            // page_home_startBtn
            let pop_close = APP.findClass_v2(data, 'pop_close');
            if(pop && pop_close){
                await pop_close.click();
                continue;
            }
  
            let page_home_startBtn = APP.findClass_v2(data, 'page_home_startBtn');
            if(page_home_startBtn){
                done = true;
                break;
            }
            await APP.sleep(1000);
        }
        this.GameClient.addTask({name:'home_to_room'});

        return true;
    }
}

module.exports = index;